import request from '@/utils/request'

export const roleAPI = {
  // 获取所有角色
  getAllRoles: () => {
    return request.get('/roles')
  },

  // 获取带权限的角色
  getRolesWithPermissions: () => {
    return request.get('/roles/permissions')
  },

  // 批量分配权限给角色
  assignPermissionsToRole: (roleId, permissionIds) => {
    return request.post('/roles/permissions', { roleId, permissionIds })
  },

  // 移除角色的所有权限
  removeAllPermissionsFromRole: (roleId) => {
    return request.delete(`/roles/${roleId}/permissions`)
  },

  // 创建角色
  createRole: (data) => {
    return request.post('/roles', data)
  },

  // 更新角色
  updateRole: (data) => {
    return request.put('/roles', data)
  },

  // 删除角色
  deleteRole: (id) => {
    return request.delete(`/roles/${id}`)
  },

  // 根据用户ID获取角色
  getRolesByUserId: (userId) => {
    return request.get(`/roles/user/${userId}`)
  }
}